class IUP_ALARM
-- Shows a modal dialog containing a message and up to three buttons.
--
-- This function shows a dialog centralized on the screen, with the message and 
-- the buttons. The ‘%N’ character can be added to the message to indicate line 
-- change.
--
-- Button 1 is set as the "DEFAULTENTER" and "DEFAULTESC". If Button 2 exists 
-- it is set as the "DEFAULTESC". If Button 3 exists it is set as the 
-- "DEFAULTESC".
--
-- The dialog uses a global attribute called "PARENTDIALOG" as the parent 
-- dialog if it is defined. It also uses a global attribute called "ICON" as 
-- the dialog icon if it is defined.

inherit
	IUP_WIDGET

create {ANY}
   alarm_one_button,
   alarm_two_buttons,
   alarm_three_buttons
	
feature {ANY}
	
	alarm_one_button (title: STRING; message: STRING; text_button_1: STRING)
		-- Create an alarm dialog with title, a message and one button.
		do
			t := title
			m := message
			bt1 := text_button_1
			type := 1
		end

	alarm_two_buttons (title, message, text_button_1, text_button_2: STRING)
		-- Create an alarm dialog with title, a message and two buttons.
		do
			t := title
			m := message
			bt1 := text_button_1
			bt2 := text_button_2
			type := 2
		end

	alarm_three_buttons (title, message, text_button_1,
                        text_button_2, text_button_3: STRING)
		-- Create an alarm dialog with title, a message and three buttons.
		do
			t := title
			m := message
			bt1 := text_button_1
			bt2 := text_button_2
			bt3 := text_button_3
			type := 3
		end

	launch: INTEGER
		-- Returns the number of the button selected by the user (1, 2 or 3) , or 
		-- 0 if failed. It fails only if button 1 is not defined.
		local
			p: POINTER
		do
			if type.is_equal(1) then
				Result := int_alarm (t.to_external, m.to_external,
				                     bt1.to_external, p, p)
			elseif type.is_equal(2) then
				Result := int_alarm (t.to_external, m.to_external,
			                        bt1.to_external,
			                        bt2.to_external, p)
			else
				Result := int_alarm (t.to_external, m.to_external,
			                        bt1.to_external,
			                        bt2.to_external,
			                        bt3.to_external)
			end
		end
	
feature {}

	t, m, bt1, bt2, bt3: STRING
	type: INTEGER

	-- Internal
	
   int_alarm (title: POINTER; message: POINTER; b1, b2, b3: POINTER): INTEGER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupAlarm"
         }"
      end
	
end -- class IUP_ALARM

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
